<?php
define('ROOT_PATH','../');
define('TEMPLATE_DIR','gmer/');
require_once(ROOT_PATH.'code/bean/config.inc.php');
require_once(ROOT_PATH.'code/class/gmer/class.admin_user.php');
require_once(ROOT_PATH.'code/bean/smarty.config.inc.php');
require_once(ROOT_PATH.'code/bean/db_config.inc.php');

$user=new gmer_user();

$session=check_login('admin/index.php');
if($user->session) {
	if(isset($_POST['old_pass'])) {
		$old_pass=$_POST['old_pass'];
		$new_pass1=$_POST['new_pass_1'];
		$new_pass2=$_POST['new_pass_2'];
		$user_name=$user->gm_name;
		if($new_pass1!=$new_pass2) js_alert('新密码重复不正确，请重新输入',true);
		$sql="select * from gm_user where gm_name='$user_name' and pass='$old_pass'";
		$res=sql_get_one($sql,__LINE__);
		if(!$res) js_alert('原密码输入不正确',true);
		$sql="update gm_user set pass='$new_pass1' where gm_name='$user_name'";
		sql_run($sql,__LINE__);
		js_alert('密码修改成功，下次请用新密码登录！',true,'index.php');
	}
	
	$tpl->assign('user',$user);	
	$tpl->assign('file_gm_info','tpl/gm_user_info.tpl');
	$tpl->display('gm_edit_password.html');
}
?>